package ftGuard;

import ftGuard.crypt.BlowfishEngine;
import ftGuard.utils.Util;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ftGuard
{
  private static final Logger _log = LoggerFactory.getLogger(ftGuard.class);
  private static byte[] _key = new byte[16];

  public static void Init()
  {
    ftConfig.load();
    if (isProtectionOn()) {
      _log.info("************[ Protection System: Start Loading ]*************");

      _log.info("************[ Protection System: Finish Loading ]*************");
      _log.info("************[ Protection System: First Guard ON ]*************");
    }
  }

  public static boolean isProtectionOn()
  {
    return ftConfig.ALLOW_GUARD_SYSTEM;
  }

  public static String getHwid(String hwid)
  {
    if ((hwid.isEmpty()) || (hwid == "") || (hwid == null) || (hwid == " "))
      return "NoClientPatch!!!";
    return Util.asHwidString(hwid);
  }

  public static byte[] getKey(byte[] key)
  {
    byte[] bfkey = {110, 36, 2, 15, -5, 17, 24, 23, 18, 45, 1, 21, 122, 16, -5, 12};
    //byte[] bfkey = { 78, 45, 28, 54, 75, 87, 41, 37, 110, 45, 1, 11, 102, 76, -5, 11 };  //rguard
    try
    {
      BlowfishEngine bf = new BlowfishEngine();
      bf.init(true, bfkey);
      bf.processBlock(key, 0, _key, 0);
      bf.processBlock(key, 8, _key, 8);
    }
    catch (IOException e)
    {
      _log.info("Bad key!!!");
    }
    return _key;
  }
}
